package hy;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;
import java.util.Random;

public class MyPartition implements Partitioner {
    Random r=new Random();
    int p=-1;
    @Override
    public int partition(String s, Object o, byte[] bytes, Object o1, byte[] bytes1, Cluster cluster) {
        System.out.println("s="+s);
        int part=r.nextInt(3);//如果是三个分区
        //return part;
       p++;
       if(p==3){
           p=0;
       }
       return p;
    }
    public void close() {}
    public void configure(Map<String, ?> map) {}
}